package com.springboot.news.controller;

import com.springboot.news.domain.dto.TagDto;
import com.springboot.news.domain.po.Result;
import com.springboot.news.domain.query.TagQuery;
import com.springboot.news.domain.vo.PageableVO;
import com.springboot.news.domain.vo.TagVo;
import com.springboot.news.service.TagService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/tag")
public class TagController {
//    vo是返回给前端展示，dto是springboot使用的类
    @Resource
    private TagService tagService;
    @GetMapping("/tagList")
    public Result<PageableVO<TagVo>> tagList(TagQuery dto) {
        return Result.success(tagService.tagList(dto));
    }
    @PostMapping("/addList")
    public Result<String> addList(@RequestBody @Validated(TagDto.Add.class) TagDto dto) {

        tagService.addList(dto);

        return Result.success("添加成功");
    }
    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam Integer id) {
        tagService.delete(id);
        return Result.success("删除成功");
    }

    @GetMapping("/detail")
    public Result<TagVo> detail(@RequestParam Integer id) {
        return Result.success(tagService.detail(id));
    }
    @PostMapping("/update")
    public Result<String> update(@RequestBody @Validated(TagDto.Update.class) TagDto dto) {
        tagService.update(dto);
        return Result.success("更新成功");
    }
}
